<?php

class LuminousGrammarPython extends LuminousGrammar
{
  public $operators = array('(?<![a-zA-Z0-9_])and(?![a-zA-Z0-9_])', 
    '(?<![a-zA-Z0-9_])not(?![a-zA-Z0-9_])', 
    '(?<![a-zA-Z0-9_])i[ns](?![a-zA-Z0-9_])',    
    '(?<![a-zA-Z0-9_])or(?![a-zA-Z0-9_])',
    '\+', '\*', '-', '\/', '=', '&[gl]t;', '!', '%', '&amp;', '\|','~',
    '\^', '\[', '\]');
    
  public $keywords = array(
    'asert|as',
    'break',
    'class|continue',
    'del|def',
    'elif|else|except|exec',
    'finally|for|from',
    'global',
    'if|import',
    'lambda',
    'print|pass',
    'raise|return',
    'try',    
    'while',
    'yield'
    );
  
  // okay so these aren't really types but it makes it more colourful.
  public $types = array('Ellipsis', 'False', 'None', 'True',
    'buffer',
    'complex',
    'dict',
    'frozenset',
    'int',
    'float',
    'long|list',
    'memoryview',
    'self|set|str',
    'tuple'
  );
  
  public $functions = array(
    'all|abs|any',
    'basestring|bin',
    'callable|chr|classmethod|cmp|compile',
    'dir|divmod',
    'enumerate|eval|execfile',
    'file|filter|format|frozenset',
    'getattr|globals',
    'hasattr|hash|help|hex',
    'id|input|is(?:instance|subclass)|iter',
    'len|locals',
    'map|max|min|memoryview',
    'next',
    'object|oct|open|ord',
    'pow|print|property',
    'range|raw_input|reduce|reload|repr|reversed|round',
    'setattr|slice|sorted|staticmethod|sum|super',
    'type',
    'unichar',
    'vars',
    'xrange',
    'zip',
    '__import__'
    );
    
  public $oo_separators = array('\.');
  
  
  // hurray for languages with easy to find grammars
  // http://docs.python.org/reference/lexical_analysis.html#numeric-literals
  // also: EPIC.
  public $numeric_regex = '
  /(?<![[:alnum:]_<$])
  (
    #hex
    (?:0[xX][0-9A-Fa-f]+[lL]*)
    |
    # binary
    (?:0[bB][0-1]+)
    |
    #octal
    (?:0[oO0][0-7]+)
    |
    # regular number
    (?:
      (?>[0-9]+)
      (?: 
        # long identifier
        [lL]
        |
        # Or a fractional part, which may be imaginary
        (?:
          (?:\.?(?>[0-9]+)?        
            (?:(?:[eE][\+\-]?)?[0-9]+)?
          )[jJ]?
        )
      )?
    )
    |
    (
      # or only after the point, float x = .1;
      \.(?>[0-9]+)(?:(?:[eE][\+\-]?)?[0-9]+)?[jJ]?
    )
  )
  /x';
  
  
    
  public function __construct()
  {
    
    $this->SetInfoAuthor( 
    array('name'=>'Mark Watkinson', 'email'=>'markwatkinson@gmail.com',
          'website'=>'http://www.asgaard.co.uk'));
    $this->SetInfoLanguage('py');
    $this->SetInfoVersion('0.5.1');    
    
    $this->delimited_types = array(
      luminous_generic_shebang(),
      luminous_generic_comment("#", "\n"),
      luminous_generic_doc_comment("'''", "'''"),
      luminous_generic_doc_comment('"""', '"""'),
      
      new LuminousDelimiterRule(0, 'STRING', LUMINOUS_REGEX, 
      '/[ruRU]{0,2}\'/', '/\'/', 'luminous_type_callback_pystring'),
      
      new LuminousDelimiterRule(0, 'STRING', LUMINOUS_REGEX, 
      '/[ruRU]{0,2}"/', '/"/', 'luminous_type_callback_pystring')    
      );
      
    $this->SetSimpleTypeRules();
    $this->simple_types[] = luminous_generic_constant();
    
  }
}

